package com.khh.action;

import lombok.Data;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by webrx on 2017-09-14.
 */

@Data
//@ParentPackage("struts-default")
//@Namespace("/")
public class ZhujieAction {

    private String fn;
    /**
     *4、扫描位于名为“struts、struts2、action或actions”的包中的注解类；

     *5、接下来，扫描匹配如下条件的文件：
         实现com.opensymphony.xwork2.Action接口；
         继承自com.opensymphony.xwork2.ActionSupport类
         文件名以Action结尾(比如UserAction、LoginAction)

     */
    //简单实现注解
    private int id;
    @Action("/myabc")
    public void abc() throws IOException {
        HttpServletResponse resp = ServletActionContext.getResponse();
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print("<!DOCTYPE html>");
        out.print("\n<html lang=\"zh\">");
        out.print("\n<head>\n<meta charset=\"utf-8\">\n<title>webrx</title>\n<body>");
        out.print("\n<h1>Struts2-Annotation-中文----</h1>" + id);
        out.print("\n</body>");
        out.print("\n</html>");
        out.flush();
        out.close();
    }


    /*注解几种类型*/
    //@Namespace() 执行的路径 前面加的路径
    //@ParentPackage("struts-default")  继承父包  可以替代<package name="default" namespace="/" extends="struts-default">
    /***
     * @Results({
         @Result(name="failure", location="fail.jsp")
         })
     */

    //vv 执行路径  location加载那个页面代码  type类型
    //@Action(value="/vv",results={@Result(name="success",type="plainText",params={"charset", "utf-8","location","/index.jsp"})})
    @Action(value="/vv",results={@Result(name="success",/*location="/${fn}.jsp",*/type="plainText",params={"charset", "utf-8","location","/${fn}.jsp"})})
    public String vv() {
        return "success";
    }


}
